package dale.web.essay.repository;

import java.util.List;

import org.apache.ibatis.session.RowBounds;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import dale.web.essay.model.Essay;

@Repository
public class EssayRepositoryBatis implements EssayRepository {

	protected SqlSessionTemplate template;

	@Autowired
	public EssayRepositoryBatis(SqlSessionTemplate template) {
		this.template = template;
	}

	public int count(Essay item) {
		return ((Integer) template.selectOne("Essay.count")).intValue();
	}

	public List<Essay> select(Essay item, int offset, int limit) {
		RowBounds bounds = new RowBounds(offset, limit);
		return template.selectList("Essay.selectList", item, bounds);
	}

	public List<Essay> select(Essay item) {
		return template.selectList("Essay.selectList", item);
	}

	public Essay select(Integer no) {
		return (Essay) template.selectOne("Essay.selectOne", no);
	}

	public int insert(Essay item) {
		return template.insert("Essay.insert", item);
	}

	public int update(Essay item) {
		return template.update("Essay.update", item);
	}

	public int delete(Integer no) {
		return template.delete("Essay.delete", no);
	}
	
}
